Create Proc Tang_Masp
as 
Begin
	declare	@Matam	char(8),		
		@Mamoi	char(8)
	select @Matam=MAX(masp) from SanPham
	if @Matam is null
		set	@Mamoi='SP-'+'0001'
	else
		set	@Mamoi='SP-' + right(rtrim(cast('0000' as char(4)) + cast((cast(right(rtrim(@MaTam),4) as int) + 1) as char(4))),4)
	select	@Mamoi
End
-------------------------------
Create Proc Tang_MaPN
as 
Begin
	declare @Matam Nvarchar(10),
			@Mamoi Nvarchar(10)
			
	select @Matam=Max(Mapn) from PhieuNhap
	if @Matam is null
		set @Mamoi='PN-'+'000001' 
	else
		set @Mamoi='PN-' + right(rtrim(cast('000000' as nvarchar(6))+ cast((cast(right(rtrim(@Matam),6) as int) + 1) as nvarchar(6))),6)
	select @Mamoi
end
--------------------------------------------------
Create Proc Tang_MaHD
as 
Begin
	declare @Matam Nvarchar(10),
			@Mamoi Nvarchar(10)
			
	select @Matam=Max(MaHD) from HoaDon
	if @Matam is null
		set @Mamoi='HD-'+'000001' 
	else
		set @Mamoi='HD-' + right(rtrim(cast('000000' as nvarchar(6))+ cast((cast(right(rtrim(@Matam),6) as int) + 1) as nvarchar(6))),6)
	select @Mamoi
end
